package lgkj.meicqt20.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import lgkj.meicqt20.R;
import lgkj.meicqt20.bean.VideoTypeEntity;


/**
 * Created by Administrator on 2017/8/9 0009.
 */

public class GalleryAdapter extends RecyclerView.Adapter<MyViewHolder> {
    private String TAG = "GalleryAdapter";
    private List<VideoTypeEntity.DataBean.TypeListBean> mDatas;
    private Context context;
    private int mpositon = 0;

    public void setPositon(int positon) {
        this.mpositon = positon;
    }


    public GalleryAdapter(Context context) {
        this.context = context;
        mDatas = new ArrayList<>();
    }

    public void setData(List<VideoTypeEntity.DataBean.TypeListBean> data) {
        if (data != null) {
            this.mDatas = data;
            this.mpositon = -1;
        }
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder myViewHolder = new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_video_top_type, parent, false));
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tv_name.setText(mDatas.get(position).getVideo_type_name());
        if (mpositon == position) {
            holder.tv_name.setTextColor(0xFF35b135);
        } else {
//            holder.tv_name.setTextColor(0xFFffffff);
            holder.tv_name.setTextColor(Color.parseColor("#ffffff"));
        }
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public VideoTypeEntity.DataBean.TypeListBean getItem(int i) {
        try {
            Log.d(TAG, mDatas.get(i).toString());
            return mDatas.get(i);
        } catch (Exception e) {
            return null;
        }
    }

}

class MyViewHolder extends ViewHolder {
    TextView tv_name;

    public MyViewHolder(View itemView) {
        super(itemView);
        tv_name = (TextView) itemView.findViewById(R.id.tv_name);
    }
}
